package com.study.securitydemo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.study.securitydemo.config.DBUserDetailManager;
import com.study.securitydemo.entity.User;
import com.study.securitydemo.mapper.UserMapper;
import com.study.securitydemo.service.IUserService;
import jakarta.annotation.Resource;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

/**
 * @author weiyongpeng
 * @ClassName: UserServiceImpl
 * @Description: 用户业务层实现类
 * @date 2024/10/26
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Resource
    private DBUserDetailManager dbUserDetailManager;

    @Override
    public boolean saveUserDetails(User user) {
        // 创建UserDetails对象
        UserDetails userDetails = org.springframework.security.core.userdetails.User.withDefaultPasswordEncoder()
                                            .username(user.getUsername())
                                            .password(user.getPassword())
                                            .build();
        dbUserDetailManager.createUser(userDetails);
        return true;
    }
}